package day0401;


import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class A01MapDemo {
    public static void main(String[] args) {
        Map<String, String> map = new HashMap<>();
        map.put("郭靖","黄蓉");
        map.put("郭靖2","黄蓉2");
        map.put("郭靖3","黄蓉3");
        System.out.println(map);
        map.remove("郭靖");
        System.out.println(map);

        //判断是否包含
        boolean found = map.containsKey("郭靖");
        System.out.println(found);
        boolean found2 = map.containsValue("黄蓉");
        System.out.println(found2);
        //增强for的形式
        for(String key : map.keySet()){
            System.out.println(key + "=" + map.get(key));
        }

        System.out.println("============map的第2种遍历方式====================");
        Set<Map.Entry<String,String>> en =map.entrySet();
        for (Map.Entry<String,String>entry:en) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key + "=" + value);
        }
        System.out.println("============map的第3种遍历方式====================");
        map.forEach(new BiConsumer<String, String>() {
            @Override
            public void accept(String key, String value) {
                System.out.println(key + "=" + value);
            }
        });
        System.out.println("============map的第4种遍历方式====================");
        map.forEach((String key,String value)->{
            System.out.println(key + "=" + value);
        });
        map.forEach((key,value)-> System.out.println(key + "=" + value));
    }
}
